package cn.edu.zzuli.nothinglink.controller;


import cn.edu.zzuli.nothinglink.entity.R;
import cn.edu.zzuli.nothinglink.entity.Teachers;
import cn.edu.zzuli.nothinglink.service.TeachersService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author suzyyy
 * @since 2021-04-08
 */
@RestController
@RequestMapping("/tea")
public class TeachersController {

    @Autowired
    TeachersService teachersService;

    @PostMapping("/login")
    public R login(@RequestBody JSONObject json) {
        if (!StringUtils.isEmpty(json.get("teaNumber"))
                && !StringUtils.isEmpty(json.get("password"))) {
            return teachersService.teaLogin(json);
        }

        return R.error().add("error", "参数不对");
    }

    @PostMapping("/register")
    public R register(@RequestBody @Valid Teachers tea) {
        return teachersService.registerTea(tea);
    }

}

